<?php
require_once(ROOT . LIBRARY .'/fields/common.inc');

class fields_email extends fields_common
{
   /**
    * Normalize Value
    *
    * @param string $value
    * @param string $lang
    */
   public function normalizeValue($value, $lang = null)
   {
      $this->value = (string)$value;
      
      return $this->value;
   }


   /**
    * Get HTML code for e-mail fields
    *
    * @param object $data
    * @return string
    */
   public function getFieldHTML($data)
   {
      $value = $data->{$this->alias}(null);

      $html  = '';
      $html .= '<input type="text" name="f['. $this->alias .']" id="f_'. $this->alias .'" ';
      if($this->required) $html .= ' class="required email" ';
      $html .= ' value="'. htmlspecialchars($value) .'" />';

      return $html;
   }


   /**
    * Validate Input Data against field type
    *
    * @param string $value
    * @param object $objectData
    * @return mixed
    */
   public function validateInput($value, $objectData = NULL)
   {
      if(!filter_var($value, FILTER_VALIDATE_EMAIL))
          $value = NULL;

      $this->value = $value;
      
      return $this->value;
   }
}